//
//  Setting.m
//  ChampoinPeso
//
//  Created by mac on 2025/2/20.
//

#import "Setting.h"
#import "SelectPop.h"

@interface Setting ()

@end

@implementation Setting

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColor.whiteColor;
    [self setupUI];
}
-(void)setupUI
{
    self.navtitleText = @"Set up";
    [self navUI];
    UIImageView *img = [UIImageView new];
    img.image = [UIImage imageNamed:@"launch_icon"];
    [self.view addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(48+MarginTop+64+20);
        make.centerX.mas_equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(108, 108));
    }];
    UIView *v1 = [UIView new];
    v1.backgroundColor = HexColor(@"#E4EEFE");
    v1.layer.cornerRadius = 8;
    [self.view addSubview:v1];
    [v1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(13);
        make.right.mas_offset(-13);
        make.top.equalTo(img.mas_bottom).offset(49);
        make.height.mas_equalTo(52);
    }];
    UIImageView *i1 = [UIImageView new];
    i1.image = [UIImage imageNamed:@"setting_tag1"];
    [v1 addSubview:i1];
    [i1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(17);
        make.centerY.mas_equalTo(v1);
        make.size.mas_equalTo(CGSizeMake(24, 24));
    }];
    UILabel *l1 = [UILabel new];
    l1.textColor = HexColor(@"#212121");
    l1.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    [v1 addSubview:l1];
    l1.text  = @"Version";
    [v1 addSubview:l1];
    [l1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(i1.mas_right).offset(15);
        make.centerY.mas_equalTo(v1);
    }];

    
    UILabel *l11 = [UILabel new];
    l11.textColor = HexColor(@"#2C64FF");
    l11.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    NSDictionary *infoDictionary = [[NSBundle mainBundle]infoDictionary];
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    l11.text  = app_Version;
    [v1 addSubview:l11 ];
    [l11 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-17);
        make.centerY.mas_equalTo(v1);
    }];

    UIView *v2 = [UIView new];
    v2.backgroundColor = HexColor(@"#E4EEFE");
    v2.layer.cornerRadius = 8;
    [self.view addSubview:v2];
    [v2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(13);
        make.right.mas_offset(-13);
        make.top.equalTo(v1.mas_bottom).offset(10);
        make.height.mas_equalTo(52);
    }];
    UIImageView *i2 = [UIImageView new];
    i2.image = [UIImage imageNamed:@"setting_tag2"];
    [v2 addSubview:i2];
    [i2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(17);
        make.centerY.mas_equalTo(v2);
        make.size.mas_equalTo(CGSizeMake(24, 24));
    }];
    UILabel *l2 = [UILabel new];
    l2.textColor = HexColor(@"#212121");
    l2.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    [v2 addSubview:l2];
    l2.text  = @"Logout";
    [v2 addSubview:l2 ];
    [l2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(i2.mas_right).offset(15);
        make.centerY.mas_equalTo(v2);
    }];
    UIImageView *imgg=[UIImageView new];
    imgg.image = [UIImage imageNamed:@"setting_turn"];
    [v2 addSubview:imgg];
    [imgg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-17);
        make.centerY.mas_equalTo(v2);
        make.size.mas_equalTo(CGSizeMake(22, 22));

    }];
    UIButton *logout = [UIButton new];
    [v2 addSubview:logout];
    [logout mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_offset(0);
    }];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"Account cancellation" forState:UIControlStateNormal];
    [btn setTitleColor:DetailColor forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:btn];
    btn.layer.cornerRadius = 20;
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(-50);
        make.centerX.mas_equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(206, 40));
    }];
    [logout addTarget:self  action:@selector(logout) forControlEvents:UIControlEventTouchUpInside];
    [btn addTarget:self  action:@selector(account) forControlEvents:UIControlEventTouchUpInside];
}

-(void)logout
{
    [[SelectPop getInstance] logOut];
    [SelectPop getInstance].logoutCommitAction = ^{
        [self logoutClick];
    };
    
}
-(void)logoutClick
{
    [DataFrameMove frameMoverForPost:@"/cham/fiftyfiveher" MoverPost:NO frameParm:@{} finish:^(id  _Nonnull info) {
        if([info[@"gardening"] intValue] == 0) {
            [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"stewardess"];
            [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"phone"];
            [[NSUserDefaults standardUserDefaults]synchronize];
            [self.navigationController popViewControllerAnimated:NO];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"logout" object:self ];

        }
    }];
}
-(void)account
{
    [[SelectPop getInstance] accountCancellation];
    [SelectPop getInstance].accountCommitAction = ^{
        [self accountClick];
    };
    [SelectPop getInstance].tAction = ^{
        [self showAutoMessage:@"Please read and agree to the agreement first" ToView:self.view];
    };

}
-(void)accountClick
{
    [DataFrameMove frameMoverForPost:@"/cham/stop" MoverPost:NO frameParm:@{} finish:^(id  _Nonnull info) {
        if([info[@"gardening"] intValue] == 0) {
            [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"stewardess"];
            [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"phone"];
            [[NSUserDefaults standardUserDefaults]synchronize];
            [self.navigationController popViewControllerAnimated:NO];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"logout" object:self ];
        }
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
